package com.ecoolex.ying.space.api.graphql;

import java.util.List;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;

import com.ecoolex.framework.common.pojo.Page;
import com.ecoolex.framework.common.pojo.Pagination;
import com.ecoolex.framework.modularize.api.service.ad.Ad;
import com.ecoolex.framework.modularize.api.service.ad.AdService;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module.Type;
import com.ecoolex.framework.web.api.graphql2.annotation.QueryField;
import com.ecoolex.framework.web.api.graphql2.annotation.Source;
import com.ecoolex.framework.web.api.graphql2.annotation.TypeField;
import com.ecoolex.ying.space.entity.MarktingCatalog;
import com.ecoolex.ying.space.entity.MarktingCatalogGoods;
import com.ecoolex.ying.space.entity.OutsourcingGoodsWithBLOBs;
import com.ecoolex.ying.space.ws.MarktingCatalogGoodsService;
import com.ecoolex.ying.space.ws.MarktingCatalogService;
import com.ecoolex.ying.space.ws.OutsourcingGoodsService;


@GraphQL2Module(type = Type.User, description = "运营目录")
public class MarktingCatalogGraphql {

    @Reference
    private MarktingCatalogService marktingCatalogService;

    @Reference
    private MarktingCatalogGoodsService marktingCatalogGoodsService;

    @Reference
    private OutsourcingGoodsService outsourcingGoodsService;

    @Autowired
    private AdService adService;
    
    @TypeField(type = MarktingCatalog.class, field = "marktingCatalogGoodsList", description = "目录商品")
    public List<MarktingCatalogGoods> marktingCatalogGoodsList(@Source MarktingCatalog source,@NonNull int size){
    	return marktingCatalogGoodsService.marktingCatalogGoodsList(source.getCatalogId(), size);
    }

    @TypeField(type = MarktingCatalog.class, field = "adList", description = "广告列表")
    public List<Ad> adList(@Source MarktingCatalog source, @NonNull String position, @NonNull int size) {
        return adService.query(position, source.getCatalogId().toString(), size);
    }

    @TypeField(type = MarktingCatalogGoods.class, field = "outsourcingGoods", description = "商品信息")
    public OutsourcingGoodsWithBLOBs outsourcingGoods(@Source MarktingCatalogGoods source) {
        return outsourcingGoodsService.getOutsourcingGoodsByIdForH5(source.getOutsourcingGoodsId());
    }

    @QueryField(field = "marktingCatalogList", description = "运营目录列表")
    public Pagination<MarktingCatalog> queryMarktingCatalog(@NonNull Page page) {
        return marktingCatalogService.queryMarktingCatalogForH5(page);
    }

    @QueryField(field = "marktingCatalogGoodsList", description = "运营目录关联商品列表")
    public Pagination<MarktingCatalogGoods> queryMarktingCatalogGoods(@NonNull Integer catalogId, @NonNull Page page) {
        return marktingCatalogGoodsService.queryMarktingCatalogGoodsByCatalogId(catalogId, page);
    }
}
